﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using V5_DAL.SqlServer;
using V5_Model;
using System.Data;

namespace V5_EShop._Class.BLL.GZ
{
    public class BLLGZProductOrderItem
    {
        private readonly DALGZProductOrderItem dal = new DALGZProductOrderItem();
        #region  Method
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(ModelGZProductOrderItem model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ModelGZProductOrderItem model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(Guid ID)
        {

            return dal.Delete(ID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            return dal.DeleteList(IDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ModelGZProductOrderItem GetModel(Guid ID)
        {

            return dal.GetModel(ID);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }

        public string getOrderPrice(string id)
        {
            return dal.getOrderPrice(id);
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ModelGZProductOrderItem> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ModelGZProductOrderItem> DataTableToList(DataTable dt)
        {
            List<ModelGZProductOrderItem> modelList = new List<ModelGZProductOrderItem>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                ModelGZProductOrderItem model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new ModelGZProductOrderItem();
                    if (dt.Rows[n]["ID"] != null && dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = new Guid(dt.Rows[n]["ID"].ToString());
                    }
                    if (dt.Rows[n]["SeqNo"] != null && dt.Rows[n]["SeqNo"].ToString() != "")
                    {
                        model.SeqNo = int.Parse(dt.Rows[n]["SeqNo"].ToString());
                    }
                    if (dt.Rows[n]["ParentID"] != null && dt.Rows[n]["ParentID"].ToString() != "")
                    {
                        model.ParentID = new Guid(dt.Rows[n]["ParentID"].ToString());
                    }
                    if (dt.Rows[n]["ProductID"] != null && dt.Rows[n]["ProductID"].ToString() != "")
                    {
                        model.ProductID = new Guid(dt.Rows[n]["ProductID"].ToString());
                    }
                    if (dt.Rows[n]["PackageSpec"] != null && dt.Rows[n]["PackageSpec"].ToString() != "")
                    {
                        model.PackageSpec = decimal.Parse(dt.Rows[n]["PackageSpec"].ToString());
                    }
                    if (dt.Rows[n]["OrderNumber"] != null && dt.Rows[n]["OrderNumber"].ToString() != "")
                    {
                        model.OrderNumber = decimal.Parse(dt.Rows[n]["OrderNumber"].ToString());
                    }
                    if (dt.Rows[n]["OrderPrice"] != null && dt.Rows[n]["OrderPrice"].ToString() != "")
                    {
                        model.OrderPrice = decimal.Parse(dt.Rows[n]["OrderPrice"].ToString());
                    }
                    if (dt.Rows[n]["OrderMoney"] != null && dt.Rows[n]["OrderMoney"].ToString() != "")
                    {
                        model.OrderMoney = decimal.Parse(dt.Rows[n]["OrderMoney"].ToString());
                    }
                    if (dt.Rows[n]["PiecePrice"] != null && dt.Rows[n]["PiecePrice"].ToString() != "")
                    {
                        model.PiecePrice = decimal.Parse(dt.Rows[n]["PiecePrice"].ToString());
                    }
                    if (dt.Rows[n]["PieceNumber"] != null && dt.Rows[n]["PieceNumber"].ToString() != "")
                    {
                        model.PieceNumber = decimal.Parse(dt.Rows[n]["PieceNumber"].ToString());
                    }
                    if (dt.Rows[n]["BulkNumber"] != null && dt.Rows[n]["BulkNumber"].ToString() != "")
                    {
                        model.BulkNumber = decimal.Parse(dt.Rows[n]["BulkNumber"].ToString());
                    }
                    if (dt.Rows[n]["Taxrate"] != null && dt.Rows[n]["Taxrate"].ToString() != "")
                    {
                        model.Taxrate = decimal.Parse(dt.Rows[n]["Taxrate"].ToString());
                    }
                    if (dt.Rows[n]["Taxamt"] != null && dt.Rows[n]["Taxamt"].ToString() != "")
                    {
                        model.Taxamt = decimal.Parse(dt.Rows[n]["Taxamt"].ToString());
                    }
                    if (dt.Rows[n]["Goodsamt"] != null && dt.Rows[n]["Goodsamt"].ToString() != "")
                    {
                        model.Goodsamt = decimal.Parse(dt.Rows[n]["Goodsamt"].ToString());
                    }
                    if (dt.Rows[n]["OrderBatchCode"] != null && dt.Rows[n]["OrderBatchCode"].ToString() != "")
                    {
                        model.OrderBatchCode = dt.Rows[n]["OrderBatchCode"].ToString();
                    }
                    if (dt.Rows[n]["Discount"] != null && dt.Rows[n]["Discount"].ToString() != "")
                    {
                        model.Discount = decimal.Parse(dt.Rows[n]["Discount"].ToString());
                    }
                    if (dt.Rows[n]["Produceddate"] != null && dt.Rows[n]["Produceddate"].ToString() != "")
                    {
                        model.Produceddate = DateTime.Parse(dt.Rows[n]["Produceddate"].ToString());
                    }
                    if (dt.Rows[n]["Validdate"] != null && dt.Rows[n]["Validdate"].ToString() != "")
                    {
                        model.Validdate = DateTime.Parse(dt.Rows[n]["Validdate"].ToString());
                    }
                    if (dt.Rows[n]["DiscountMoney"] != null && dt.Rows[n]["DiscountMoney"].ToString() != "")
                    {
                        model.DiscountMoney = decimal.Parse(dt.Rows[n]["DiscountMoney"].ToString());
                    }
                    if (dt.Rows[n]["DeliverNumber"] != null && dt.Rows[n]["DeliverNumber"].ToString() != "")
                    {
                        model.DeliverNumber = decimal.Parse(dt.Rows[n]["DeliverNumber"].ToString());
                    }
                    if (dt.Rows[n]["Remark"] != null && dt.Rows[n]["Remark"].ToString() != "")
                    {
                        model.Remark = dt.Rows[n]["Remark"].ToString();
                    }
                    if (dt.Rows[n]["Remark1"] != null && dt.Rows[n]["Remark1"].ToString() != "")
                    {
                        model.Remark1 = dt.Rows[n]["Remark1"].ToString();
                    }
                    if (dt.Rows[n]["Remark2"] != null && dt.Rows[n]["Remark2"].ToString() != "")
                    {
                        model.Remark2 = dt.Rows[n]["Remark2"].ToString();
                    }
                    if (dt.Rows[n]["Remark3"] != null && dt.Rows[n]["Remark3"].ToString() != "")
                    {
                        model.Remark3 = dt.Rows[n]["Remark3"].ToString();
                    }
                    if (dt.Rows[n]["Remark4"] != null && dt.Rows[n]["Remark4"].ToString() != "")
                    {
                        model.Remark4 = dt.Rows[n]["Remark4"].ToString();
                    }
                    if (dt.Rows[n]["TimeStamp"] != null && dt.Rows[n]["TimeStamp"].ToString() != "")
                    {
                        model.TimeStamp = DateTime.Parse(dt.Rows[n]["TimeStamp"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere)
        {
            return dal.GetList(PageSize, PageIndex, strWhere);
        }

        #endregion  Method
    }
}